using ShawnFramework;
using UnityEngine;

public class EnemySpawner : MonoBehaviour
{
    [Header("敌人生成时间间隔")]
    public float duration = 0.5f;
    
    private float _timer = 0;
    private void Update()
    {
        _timer += Time.deltaTime;
        if (_timer >= duration)
        {
            _timer = 0;
            // 生成某类型敌人
            SpawnByType(0);
        }
    }

    private void SpawnByType(int type)
    {
        var ctl = GameController.Instance;
        var enemy = ObjectPool.Global.Spawn(PoolElemTypeEnum.Enemy00, ctl.enemyPrefab);
        var pos = new Vector2(RandomUtil.NormalRandom(-800, 800), RandomUtil.NormalRandom(-800, 800));
        enemy.Position(pos);
        enemy.Active(true);
    }
}
